package com.example.lib_common.event

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData

/**
 * @author yaotianxue
 * @description 事件总线封装
 * @date 2025/2/10
 */
object LiveDataBus {
    private val mBus = HashMap<String, MutableLiveData<*>>() // 事件总线

    /**
     * 根据键获得LiveData
     */
    fun <T> with(key:String):MutableLiveData<T>{
        if(!mBus.containsKey(key)){
            mBus[key] = MutableLiveData<T>()
        }
        return mBus[key] as MutableLiveData<T>
    }
}